<template>
  <ul class="tab-bar">
    <li
      v-for="(route, index) in tabRoutes"
      :key="route.path"
      :class="{active: $route.path.split('/').includes(route.path.slice(1))}"
      @click="jump(route.path, index)"
    >
      <i class="iconfont" v-html="route.meta.icon"></i>
      <span>{{ route.meta.title }}</span>
      <span class="badge" v-if="route.meta.isBadge && totalAmount > 0">{{ totalAmount | formatNumber }}</span>
    </li>
    <!-- <li
      v-for="(route, index) in tabRoutes"
      :key="route.path"
      :class="{active: currentIndex === index}"
      @click="jump(route.path, index)"
    >
      <i class="iconfont" v-html="route.meta.icon"></i>
      <span>{{ route.meta.title }}</span>
    </li> -->
  </ul>
</template>

<script>
import routes from '@/router/routes'

export default {
  name: 'TabBar',

  data () {
    return {
      // currentIndex: 0
    }
  },

  computed: {
    totalAmount () {
      return this.$store.getters.totalAmount
    },
    tabRoutes () {
      // return routes.filter(route => route.meta && route.meta.isTab)
      return routes.filter(route => route.meta?.isTab)
    }
  },

  methods: {
    jump (path, index) {
      // this.currentIndex = index
      this.$router.push(path)
    }
  }
}
</script>

<style lang="less" scoped>
@font-face {
  font-family: 'iconfont';  /* project id 2408861 */
  src: url('//at.alicdn.com/t/font_2408861_so21ip5znq.eot');
  src: url('//at.alicdn.com/t/font_2408861_so21ip5znq.eot?#iefix') format('embedded-opentype'),
  url('//at.alicdn.com/t/font_2408861_so21ip5znq.woff2') format('woff2'),
  url('//at.alicdn.com/t/font_2408861_so21ip5znq.woff') format('woff'),
  url('//at.alicdn.com/t/font_2408861_so21ip5znq.ttf') format('truetype'),
  url('//at.alicdn.com/t/font_2408861_so21ip5znq.svg#iconfont') format('svg');
}

.iconfont{
  font-family:"iconfont" !important;
  font-size:16px;font-style:normal;
  -webkit-font-smoothing: antialiased;
  -webkit-text-stroke-width: 0.2px;
  -moz-osx-font-smoothing: grayscale;
}

.tab-bar {
  display: flex;
  border-top: 1px solid #eaeaea;

  li {
    flex: 1;
    height: 64px;
    display: flex;
    flex-direction: column;
    justify-content: space-around;
    align-items: center;
    position: relative;

    i {
      font-size: 32px;
    }

    &.active {
      color: #d81e06;
      font-weight: 700;
    }

    .badge {
      width: 24px;
      height: 24px;
      position: absolute;
      top: -12px;
      right: 16px;
      background: #d81306;
      color: #FFFFFF;
      text-align: center;
      line-height: 24px;
      border-radius: 12px;
      font-size: 12px;
    }
  }
}
</style>
